// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (a%=p; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}

int n, k;

const int N = 2e5+50;

vector<int> G[N];

int siz[N];

bool leaf[N];

int dep[N];


void dfs(int u, int fa) {
	dep[u] = dep[fa] + 1;
	for (int v : G[u]) {
		if (v == fa)
			continue;
		dfs(v, u);
	}
}

void dfs2(int u, int fa) {
	siz[u] = 1;
	for (int v : G[u]) {
		if (v == fa)
			continue;
		dfs2(v, u);
		siz[u] += siz[v];
	}
}

int main(int argc, char const *argv[]) {
    // code
	scanf("%d%d", &n, &k);
	for (int i=1; i<=n-1; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}

	dfs(1, 1);

	vector<pair<int, int>> vleaf;
	vleaf.reserve(n);
	for (int i=2; i<=n; ++i) {
		vleaf.emplace_back(dep[i], i);
	}
	int ans = 0;
	for (int i=0; i<min(sz(vleaf), k); ++i)
		leaf[vleaf[i].second] = 1;
	if (k <= sz(vleaf)) {
		sort(vleaf.begin(), vleaf.end());
		reverse(vleaf.begin(), vleaf.end());

		for (int i=0; i<k; ++i)
			ans += vleaf[i].first - 1;
	} else {
		dfs2(1, 1);

		vector<pair<int, int>> candi;
		candi.reserve(n);

		for (int i=1; i<=n; ++i) {
			if (!leaf[i])
				candi.emplace_back(siz[i], i);
		}
		sort(candi.begin(), candi.end());
		reverse(candi.begin(), candi.end());
		for (int i=0; i<n-k; ++i) {
			ans += candi[i].first;
		}

	}

	cout << ans << endl;


    return 0;
}